package JDBC_Test.book;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ResourceBundle;

import java.sql.Statement;

public class JDBCUtil {
	private static ResourceBundle rb = ResourceBundle.getBundle("JDBC_Test.book.jdbc");
	
	private static String className = rb.getString("driver");
	private static String user = rb.getString("user");
	private static String password = rb.getString("password");
	private static String url = rb.getString("url");
	
	//加载驱动
	static {
		try {
			Class.forName(className);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * 获得连接
	 * @return
	 * @throws SQLException
	 */
	public static Connection geConnection() throws SQLException {
		return DriverManager.getConnection(url,user,password);
	}
	/**
	 * 关闭连接
	 * @param con
	 * @param st
	 * @param ps
	 * @throws SQLException
	 */
	public static void close(Connection con,Statement st,PreparedStatement ps) throws SQLException {
		if(con!=null) {
			con.close();
			con = null;
			
		}
		if(st!=null) {
			st.close();
			st =null;
			
		}
		if(ps!=null) {
			ps.close();
			ps=null;
		}
		
	}
	/**
	 * 构造方法私有化
	 */
	private JDBCUtil() {
		
	}

}
